/* eslint no-param-reassign: 0  */

import Vue from "vue";
import Vuex from "vuex";
import sessionStore from "store2";

Vue.use(Vuex);
const userStore = new Vuex.Store({
  state: {
    isLoading: false, // loading状态
    usrInfo: {} // 用户信息
  },
  getters: {
    // 计算过滤
    getUsrInfo(state) {     // 获取用户信息
      // 获取用户信息
      state.usrInfo = sessionStore.local("usrInfo");
      if (!state.usrInfo) state.usrInfo = {}
      return state.usrInfo;
    },
    getLastLogin(state) {     // 获取用户信息
      // 获取用户信息
      state.lastLoginMobile = sessionStore.local("lastLogin");
      return state.lastLoginMobile;
    }
  },
  mutations: {
    // 修改状态
    updateLoadingStatus(state, status) {
      // 修改loading状态
      state.isLoading = status;
    },
    setLastLogin(state, lastLoginMobile) {
      // 设置最后登录信息
      state.lastLoginMobile = lastLoginMobile;
      sessionStore.local("lastLogin", lastLoginMobile);
    },
    setUsrInfo(state, usrInfo) {
      // 设置用户信息
      state.usrInfo = usrInfo;
      sessionStore.local("usrInfo", usrInfo);
    },
    removeUsrInfo(state) {
      // 删除用户信息
      state.usrInfo = {};
      sessionStore.local.remove("usrInfo");
    },
    setSign(state, sign) {     // 设置签名
      // 设置用户信息
      state.sign = sign;
      sessionStore.local("sign", sign);
    },
    showToast(state, content) {
      // 展示toast提示框
      state.toastContent = content;
      state.isShowToast = true;
    },
    hideToast(state) {
      // 隐藏toast提示框
      state.toastContent = "";
      state.isShowToast = false;
    }
  },
  actions: {
    // 异步修改状态
    // setUserInfo({ commit }, user) {
    //   commit('setUserInfo', user);
    // }
  }
});

export default userStore;
